package com.example.picturestorage.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class MyMVCInterceptor implements HandlerInterceptor {

    private final static Logger LOGGER = LoggerFactory.getLogger(MyMVCInterceptor.class);
    
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LOGGER.info("---------------pre--------------");
        LOGGER.info(request.getContextPath());
        LOGGER.info(String.valueOf(response.getHeaderNames()));
        LOGGER.info("handler " + handler);
        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        LOGGER.info("---------------after--------------");
        LOGGER.info(request.getContextPath());
        LOGGER.info(String.valueOf(response.getHeaderNames()));
        LOGGER.info("handler " + handler);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        LOGGER.info("---------------post--------------");
        LOGGER.info(request.getContextPath());
        LOGGER.info(String.valueOf(response.getHeaderNames()));
        LOGGER.info("handler " + handler);
    }
}
